<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Ruby language</title>
<link rel="stylesheet" href="/cfg/format.css" type="text/css">
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta name="keywords" content="Ruby, tutorial, programming language, learn Ruby, Linux">
<meta name="description" content="This part of the Ruby tutorial describes the Ruby language.">
<meta name="language" content="en">
<meta name="author" content="Jan Bodnar">
<meta name="distribution" content="global">

</head>

<body>

<div class="container2">

<div id="wide_ad" class="ltow">
<script type="text/javascript"><!--
google_ad_client = "pub-9706709751191532";
/* 160x600, August 2011 */
google_ad_slot = "2484182563";
google_ad_width = 160;
google_ad_height = 600;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>


<div class="content2">

<a href="/" title="Home">Home</a>&nbsp;
<a href="..">Contents</a>



<h1>Ruby</h1>

<p>
In this part of the Ruby tutorial, we will introduce the 
Ruby programming language. 
</p>


<h2>Goal</h2>

<p>
The goal of this tutorial is to get you started with the Ruby
programming language. The tutorial covers the core of the Ruby language. 
Variables, expressions, collections, control structures and other core features. 
It also describes some more advanced concepts like object-oriented programming,
or regular expressions. It is not a complete coverage of the language. 
The tutorial was created on Ubuntu Linux. 
</p>

<div class="big_hor">
<script type="text/javascript"><!--
google_ad_client = "ca-pub-9706709751191532";
/* big_horizontal */
google_ad_slot = "2904953388";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>


<h2>Ruby</h2>

<p> 
<img src="/img/lang/ruby/logo.png" style="float: left; margin-right:10" alt="Ruby logo"> 
<b>Ruby</b> is a dynamic, reflective, general-purpose object-oriented programming language.
The original author is a Japanese programmer <b>Yukihiro Matsumoto</b>. Ruby first appeared in 1995. 
</p> 

<p> 
Ruby supports various programming paradigms. This includes object orientation, reflection, imperative
and reflective programming. Ruby language was influenced primarily by Perl, Smalltalk, Eiffel, and Lisp.
Unlike languages like Java, C# or C, Ruby has no official specification. Instead the original C implementation
of the Ruby language serves as a de facto reference. There are other implementations 
of the Ruby language like JRuby, IronRuby or MacRuby. 
</p> 
 
<p> 
The official web site is <a href="http://www.ruby-lang.org/">ruby-lang.org</a>.
</p> 

<h2>Popularity</h2>

<p>
There are hundreds of programming languages in use today. Ruby
belongs to the most popular ones. The <a href="http://langpop.com/">langpop.com</a> and
<a href="http://www.tiobe.com/index.php/content/paperinfo/tpci/index.html">tiobe</a> sites
put Ruby around the 10th place. Ruby on Rails, a very popular web application framework
is the first killer application created in Ruby.                                                                   
</p>

<h2>Interactive interpreter</h2>

<p>
We can run Ruby statements in a script or in an interactive interpreter. 
In this tutorial, we will use the interactive Ruby session to demonstrate 
some smaller code fragments. Larger code examples are to be put in
Ruby scripts. 
</p>

<pre class="code">
$ irb
irb(main):001:0> puts RUBY_VERSION
1.8.7
=> nil
</pre>

<p>
This is an example of the Ruby interactive session.
We print the value of a special RUBY_VERSION constant to 
the console. It is set to the version of the
current Ruby in use. 
</p>



<h2>Ruby scripts</h2>

<p>
We will have our first simple example of a Ruby script. 
</p>

<pre class="code">
#!/usr/bin/ruby

# first.rb 

puts "This is Ruby"
</pre>

<p>
In this script, we print a message to the console. 
</p>

<pre class="explanation">
#!/usr/bin/ruby
</pre>

<p>
Every script in the UNIX starts with a shebang. The shebang is the first two 
characters in the script: <b>#!</b>. The shebang is followed by the path 
to the interpreter, which will execute our script. The /usr/bin/ is the
most common location for the Ruby interpreter. It could also be located in
/usr/local/bin/ or elsewhere. 
</p>

<pre class="explanation">
# first.rb 
</pre>

<p>
Comments in Ruby are preceded by a # character. 
</p>

<pre class="explanation">
puts "This is Ruby"
</pre>

<p>
The <code>puts</code> method prints a string to the console. 
</p>

<pre class="code">
$ which ruby
/usr/bin/ruby
</pre>

<p>
The path to the Ruby interpreter can be found using the which command.
</p>

<pre class="code">
$ chmod +x first.rb 
$ ./first.rb 
This is Ruby
</pre>

<p>
We make the script executable with the chmod command. And execute it.
</p>


<h2>Sources</h2>

<p>
The following sources were used to create this tutorial:
</p>

<ul>
  <li><a href="http://www.ruby-lang.org/">ruby-lang.org</a></li>
  <li><a href="http://ruby-doc.org/">ruby-doc.org</a></li>
  <li><a href="http://en.wikipedia.org/wiki/Ruby_(programming_language)">Ruby article on wikipedia.org</a></li>
  <li><a href="http://ruby.runpaint.org/">ruby.runpaint.org</a></li>
</ul>


<p>
In this part of the Ruby tutorial, we have introduced the Ruby language. 
</p>

<div class="botNav, center">
<span class="botNavItem"><a href="/">Home</a></span> ‡ <span class="botNavItem"><a href="..">Contents</a></span> ‡ 
<span class="botNavItem"><a href="#">Top of Page</a></span>
</div>

<div class="footer">
<div class="signature">
<a href="/">ZetCode</a> last modified December 14, 2011  <span class="copyright">&copy; 2007 - 2013 Jan Bodnar</span>
</div>
</div>

</div> <!-- content -->

</div> <!-- container -->

</body>
</html>
